{% extends 'layout/base.html' %}

{% block right_content%}
<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li class="layui-this">修改密码</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form>
                            {% csrf_token %}

                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="newpassword" required lay-verify="required"
                                        autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">8到16个字符</div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="repassword" required
                                        lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <input type="text" hidden='true'  name='key' value="{{message}}" >
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="resetPass" lay-submit>立即修改</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% endblock %}

    {% block script %}

    <script>
        layui.use(['form', 'jquery'], function () {
            var form = layui.form,
                $ = layui.jquery

            form.on('submit(resetPass)', function (data) {
                $.ajax({
                    url: 'reset_password',
                    method: 'post',
                    data: data.field,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code == 200) {
                            layer.msg((res.msg));
                            setTimeout(function () {
                                window.location.href = "/account/login"
                            }, 500)
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                });
                return false
            });
        });
    </script>
    {% endblock %}